package com.control.qct.businesssteward.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.adapter.ReplenishmentListAdapter;
import com.control.qct.businesssteward.base.BaseFragment;
import com.control.qct.businesssteward.entity.TabEntity;
import com.control.qct.businesssteward.model.ReplenishmentListModel;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2018/1/16 0016.
 */

public class ReplenishmentFragment extends BaseFragment implements OnTabSelectListener, ReplenishmentListAdapter
        .ICallbackClickListener {
    @BindView(R.id.ctl_replenishment_top)
    CommonTabLayout mCtlReplenishmentTop;

    @BindView(R.id.rv_replenishment)
    RecyclerView mRvReplenishment;

    private final String[] mTitles = {"全部", "审核中", "已发货", "待收货"};
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private List<ReplenishmentListModel> mReplenishmentListBeanList;
    private List<Integer> mGoodsPicture = new ArrayList<>();
    private ReplenishmentListAdapter mReplenishmentListAdapter;

    @Override
    protected View initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        return inflater.inflate(R.layout.fragment_replenishment, container, false);
    }

    @Override
    protected void initView(View view) {
        activity.setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.finish();
            }
        });
        activity.setTitle("补货");
        activity.setRightIcon("新增", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.replaceFragment(R.id.fl_content, new NewReplenishmentFragment(), true);
            }
        });
        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i], 0, 0));
        }
        mCtlReplenishmentTop.setTabData(mTabEntities);
        mCtlReplenishmentTop.setOnTabSelectListener(this);
        setReplenishmentListBeanList();
        mRvReplenishment.setLayoutManager(new LinearLayoutManager(activity));
        mReplenishmentListAdapter = new ReplenishmentListAdapter(mReplenishmentListBeanList);
        mRvReplenishment.setAdapter(mReplenishmentListAdapter);
        mReplenishmentListAdapter.setCallbackClickListener(this);
        mReplenishmentListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                activity.replaceFragment(R.id.fl_content, new ReplenishmentOrderDetailFragment(), true);
            }
        });

    }

    public void setReplenishmentListBeanList() {
        mReplenishmentListBeanList = new ArrayList<>();
        mGoodsPicture.add(R.drawable.icon_placeholder);
        mGoodsPicture.add(R.drawable.icon_placeholder);
        mGoodsPicture.add(R.drawable.icon_placeholder);
        mReplenishmentListBeanList.add(new ReplenishmentListModel("245144", 0, mGoodsPicture, 2512, 12521.00f));
        mReplenishmentListBeanList.add(new ReplenishmentListModel("245144", 1, mGoodsPicture, 2512, 12521.00f));
        mReplenishmentListBeanList.add(new ReplenishmentListModel("245144", 1, mGoodsPicture, 2512, 12521.00f));
        mReplenishmentListBeanList.add(new ReplenishmentListModel("245144", 2, mGoodsPicture, 2512, 12521.00f));
    }

    @Override
    public void onClickListener(int position) {
        activity.replaceFragment(R.id.fl_content, new ReplenishmentOrderDetailFragment(), true);
    }

    @Override
    public void onTabSelect(int position) {

    }

    @Override
    public void onTabReselect(int position) {

    }
}
